appxbAd();
function appxbAd(){
$(document).ready(function(){
    //默认展开
    var adTip = wfGetCookie('adTip');
    /*显示 优惠券提示*/
    if(adTip != 1)
    {
        unfold();
    }

   
})

$(window).resize(function() {
    var imgxs = $("#ad-fold").find("img").attr("img-xs");
    var imgnormal = $("#ad-fold").find("img").attr("img-normal");
    if($(window).width()<1400){
        $("#ad-fold").find("img").attr('src',imgxs);
    }else{
        $("#ad-fold").find("img").attr('src',imgnormal);
    }
})

$("#popimg-close").mouseout(function(){
	rotate();
});

$("#popimg-close").mouseover(function(){
	rotate();
});

$("#popimg-close").click(function(){
	fold();
	stateFold();
});

$("#ad-fold").click(function(){
	unfold();
	stateSmallClick();
});


//关闭按钮悬浮动效
function rotate(){
    if($("#popimg-close").hasClass("rotate180")){
        $("#popimg-close").removeClass("rotate180");
    }else{
        $("#popimg-close").addClass("rotate180");
    }
}
//展开
function unfold(){

    if(isOldBrowser()){
        $("#ad-fold").addClass('hid');
        $("#ad-con").css('right','0');
    }else{
        $("#ad-fold").css('transition-delay','0s').css('left','-116px');
        $("#ad-con").css('transition-delay','.5s').css('right','0').addClass("unfold");
    }


    stateUnfold();
}
//收起
function fold(){
   
	if(isOldBrowser()){
		$("#ad-con").css('right','100%');
		$("#ad-fold").removeClass('hid');
	}else{
		$("#ad-con").css('transition-delay','0s').css('right','100%').removeClass("unflod");
		$("#ad-fold").css('transition-delay','.5s').css('left','0');
	}

	wfSetCookie('adTip',1,720,document.domain);
}

//大图点击关闭事件
function stateFold()
{
	if(typeof(_hmt) != 'undefined')
	{
    		_hmt.push(['_trackEvent','ad_web_showcase','ad_web_showcase_fold']);
	}
}

//展开事件
function stateUnfold()
{
	if(typeof(_hmt) != 'undefined')
	{
		_hmt.push(['_trackEvent','ad_web_showcase','ad_web_showcase_unfold']);
    	}
}

//小图点击事件
function stateSmallClick()
{
	if(typeof(_hmt) != 'undefined')
	{
    		_hmt.push(['_trackEvent','ad_web_showcase','ad_web_showcase_small_click']);
	}
    //console.log('stateSmallClick');
}

function isOldBrowser(){
    if(navigator.appName == "Microsoft Internet Explorer"&&parseInt(navigator.appVersion.split(";")[1].replace(/[ ]/g, "").replace("MSIE",""))<9){
        return true;
    }else{
        return false;
    }
}

function wfGetCookie(name)
{
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;
}

function wfSetCookie(c_name,value,minute,domain)
{
	var exdate=new Date();
	exdate.setTime(exdate.getTime()+60*1000*minute);
	document.cookie=c_name+ "=" +escape(value)+";path=/;domain="+domain+
		((minute==null) ? "" : ";expires="+exdate.toGMTString());
}

}



